function callAJAX(url, pageElement, callMessage) {
    document.getElementById(pageElement).innerHTML = callMessage;
    try {
        req = new XMLHttpRequest(); /* e.g. Firefox */
    } catch(e) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        /* some versions IE */
        } catch (e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            /* some versions IE */
            } catch (E) {
                req = false;
            }
        }
    }

    req.onreadystatechange = function() {
        responseAJAX(pageElement);
    };
    req.open("GET",url,true);
    req.send();

}

function responseAJAX(pageElement) {
    var output = '';
    if(req.readyState == 4) {
        if(req.status == 200) {
            output = req.responseText;
            document.getElementById(pageElement).innerHTML = output;
        }
    }
}
function checkAll(field)
{
    for (i = 0; i < field.length; i++)
        field[i].checked = true ;
}

function uncheckAll(field)
{
    for (i = 0; i < field.length; i++)
        field[i].checked = false ;
}
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
    if(!document.forms[FormName])
        return;
    var objCheckBoxes = document.forms[FormName].elements[FieldName];
    if(!objCheckBoxes)
        return;
    var countCheckBoxes = objCheckBoxes.length;
    if(!countCheckBoxes)
        objCheckBoxes.checked = CheckValue;
    else
        // set the check value for all check boxes
        for(var i = 0; i < countCheckBoxes; i++)
            objCheckBoxes[i].checked = CheckValue;
}
function selectToggle(toggle, form) {

    var myForm = document.forms[form];
    
    //document.write(myForm.toString());
    for( var i=0; i < myForm.length; i++ ) {
         
        if(toggle) {
            myForm.elements[i].checked = "checked";
        }
        else {
            myForm.elements[i].checked = "";
        }
    }
}
function queryDB(str,table,form)
{
    var url="index.php?site="+table+"&";
    for( var i=0; i < form.length; i++ ){
        url=url+form.elements[i].name+"="+form.elements[i].value+"&";
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("grid").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}
/*
function callForSite(url,target,action,form)
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById(target).innerHTML=xmlhttp.responseText;
             
        }
    }
    url="index.php?site="+url;
    if(action!=null)
        url=url+'&action='+action;
    if(form!=null)
        url=url+'&message='+form.elm1.value;
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}*/
function submitForm(url,target,action,form)
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById(target).innerHTML=xmlhttp.responseText;

        }
    }
    url="index.php?site="+url;
    if(action!=null)
        url=url+'&action='+action+'&';
    if(form!=null)
        for( var i=0; i < form.length; i++ ){
            url=url+form.elements[i].name+"="+form.elements[i].value+"&";
        }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}
function callForSite(site,target,action,form){
    target='#'+target;
    $.post('index.php', {site: site, action: action},
    function(output){
        $(target).html(output).fadeIn(200, hideLoader);
    });

}
function showLoader(){

    $('.search-background').fadeIn(200);
}

function hideLoader(){

    $('.search-background').fadeOut(200);
};
